package cn.edu.ctbu.test.service.impl;

import cn.edu.ctbu.test.domain.Student;
import cn.edu.ctbu.test.dao.StudentRepository;
import cn.edu.ctbu.test.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.*;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentRepository studentRepository;

    @Override
    public List<Student> findAll(){

        return studentRepository.findAll();
    }



    @Override
    public Page<Student> findAll(Pageable pageable) {


        return studentRepository.findAll(pageable);

    }


    @Override
    public Page<Student> findAll(Example<Student> student, Pageable pageable){

        return studentRepository.findAll(student,pageable);
    }



    public List<Student> findByNameAndPassWord(String name,String password){

        return studentRepository.findByNameAndPassWord(name,password);
    }


    /**
     * zsgc
     * @param
     * @return
     */

    public Student search(Long Id){

        return studentRepository.findById(Id).get();
    }

    public Student insert(Student student){

        return studentRepository.save(student);
    }

    public void delete(Long Id){
        Student student=new Student();
        student.setId(Id);
        studentRepository.delete(student);
    }

    public Student getById(Long Id){

        Student student=studentRepository.findById(Id).orElse(null);

        return student;
    }

    public Student update(Student student){

        return  studentRepository.save(student);
    }
    public List<Student> findByName(String name){

        return studentRepository.findByName(name);

    }

}
